<?php

use Illuminate\Database\Seeder;

class AdminUserGenerate extends Seeder
{
    protected $faker;

    public function __construct(Faker\Generator $faker)
    {
        $this->faker = $faker;
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $permissions = [
            'basic' => \App\B2BProject\Admin\Authority\Rbac\Permission::create([
                'name'         => 'basic',
                'display_name' => '基本权限',
                'description'  => '基本权限',
            ])->id,
            'grant' => \App\B2BProject\Admin\Authority\Rbac\Permission::create([
                'name'         => 'grant',
                'display_name' => '授权权限',
                'description'  => '授权权限',
            ])->id,
        ];

        $roles = [
            'normal' => \App\B2BProject\Admin\Authority\Rbac\Role::create([
                'name'         => 'normal',
                'display_name' => '普通管理员',
                'description'  => '普通管理员',
            ]),
            'super'  => \App\B2BProject\Admin\Authority\Rbac\Role::create(['name'         => 'super',
                                                                           'display_name' => '超级管理员',
                                                                           'description'  => '超级管理员',
            ]),
        ];

        $roles['normal']->permissions()->attach($permissions['basic']);
        $roles['super']->permissions()->attach([$permissions['basic'], $permissions['grant']]);

        \App\B2BProject\Admin\Administrator::create([
            'user'     => 'admin',
            'password' => bcrypt('123456'),
            'email'    => $this->faker->email,
        ])->roles()->attach($roles['super']->id);

        \App\B2BProject\Admin\Administrator::create([
            'user'     => 'admin-tester',
            'password' => bcrypt('123456'),
            'email'    => $this->faker->email,
        ])->roles()->attach($roles['normal']->id);
    }
}
